package com.jing.weibo.service.system;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jing.system.model.PageCls;
import com.jing.system.utils.DateUtil;
import com.jing.weibo.mapper.system.StatisticsMapper;
import com.jing.weibo.pojo.user.UserInfo;

/**
 * 统计的Service
 * @author jing.yue
 * @version 2012/09/26 1.0.0
 */
@Component
public class StatisticsService {

	@Autowired
	private StatisticsMapper statisticsMapper;

	/**
	 * 获取总用户数
	 * @return
	 * @throws Exception
	 */
	public Integer findCountUser() throws Exception {
		return statisticsMapper.findCountUser();
	}

	/**
	 * 获取今日活跃用户数
	 * @return
	 * @throws Exception
	 */
	public Integer findCountActiveUser() throws Exception {
		String stringtime = DateUtil.dateToString(DateUtil.getTime(), DateUtil.FMT_YYYY_MM_DD);
		return statisticsMapper.findCountActiveUser(stringtime);
	}

	/**
	 * 获取今日新增用户数
	 * @return
	 * @throws Exception
	 */
	public Integer findCountAddUser() throws Exception {
		String stringtime = DateUtil.dateToString(DateUtil.getTime(), DateUtil.FMT_YYYY_MM_DD);
		return statisticsMapper.findCountAddUser(stringtime);
	}

	/**
	 * 分页获取最近登录的用户列表
	 * @param userInfo
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> findlatelyLoginUser(UserInfo userInfo) throws Exception {
		List<UserInfo> userInfos = statisticsMapper.findlatelyLoginUser(userInfo);
		Integer countSize = statisticsMapper.findlatelyLoginUserCount(userInfo);
		PageCls pageCls = PageCls.setPageCls(userInfo.getPage(), userInfo.getSize(), null, null, countSize, userInfos.size(), userInfos);
		return pageCls.getPageInfo();
	}

}
